package com.openatc.agent.model;

import com.google.gson.Gson;
import com.openatc.core.util.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.logging.Logger;

/**
 * @author ：panleilei
 * @description
 * @modified By：
 * @version:
 * @date ：Created in 2024/10/25 10:28
 */
@Component
public class QYDeviceStatusManager {
    private Gson gson = GsonUtil.getInstance();
    @Value("${quanyu.kafka.servers}")
    private String bootstrapServers;

    @Value("${quanyu.device.status.report-enable}")
    private boolean reportDeviceStatus;

    @Autowired(required = false)
    @Qualifier("QYKafkaTemplate")
    private KafkaTemplate QYKafkaTemplate;

    public void pushDeviceStatus(DeviceStatus status) {
        if (!reportDeviceStatus) return;
        sendStatus(status);
    }

    public boolean isReportDeviceStatus() {
        return reportDeviceStatus;
    }


    private void sendStatus(DeviceStatus status) {
        QYKafkaTemplate.send(DeviceStatus.TOPIC,status.getDevGbId(), gson.toJson(status));
    }

    public String getBootstrapServers() {
        return bootstrapServers;
    }
}
